/**
 * 防抖：一段时间后执行一次函数
 * 节流：一段时间内只执行一次函数
 */
function throttle(fn, delay) {
    let timer = null
    return function (...args) {
        if (timer) return
        timer = setTimeout(() => {
            fn.apply(this, args)
            timer = null
        }, delay)
    }
}

function debounce(fn, delay) {
    let timer = null
    return function (...args) {
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, args)
        }, delay)
    }
}
// 函数柯里化
function sum(a) {
    return function () {
        return a
    }
}
let add = sum(1)
// console.log(add(2)) // 3
console.log(sum(1)) // 1